package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.model.domain.Bed;
import com.example.mybatisplus.mapper.BedMapper;
import com.example.mybatisplus.model.domain.User;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.model.dto.vo.BedNumber4BuildingsVO;
import com.example.mybatisplus.model.dto.vo.StatsVO;
import com.example.mybatisplus.model.vo.StatisticVO;
import com.example.mybatisplus.service.BedService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2024-07-16
 */
@Service
public class BedServiceImpl extends ServiceImpl<BedMapper, Bed> implements BedService {

    @Autowired
    private BedMapper bedMapper;


    @Override
    public List<StatsVO> getBedByID() {
        return baseMapper.getBedByID();

    }

    @Override
    public List<StatisticVO> spareBed() {
        return baseMapper.spareBed();
    }

    @Override
    public List<BedNumber4BuildingsVO> getBedByBuilding() {
        return bedMapper.getBedByBuilding();
    }

    @Override
    public Page<Bed> pageList(Bed bed, PageDTO dto) {
        QueryWrapper<Bed> wrapper = new QueryWrapper<>();
        Page<Bed> page =new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPagesize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public Page<Bed> getUnusedBedList(Bed bed, PageDTO dto) {
        QueryWrapper<Bed> wrapper = new QueryWrapper<>();
        if(Objects.nonNull(bed.getYqBed())){
            wrapper.like("yq_bed",bed.getYqBed());
        }
        if(Objects.nonNull(bed.getBuildingsBed())){
            wrapper.eq("buildings_bed",bed.getBuildingsBed());
        }
        if(Objects.nonNull(bed.getFloorBed())){
            wrapper.eq("floor_bed",bed.getFloorBed());
        }
        wrapper.eq("availability_bed",0);
        Page<Bed> page = new Page<>();
        page.setCurrent(dto.getPageNo());
        page.setSize(dto.getPagesize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }
}
